package androidx.blogger.tasks;

import com.google.gwt.user.client.rpc.AsyncCallback;

import androidx.blogger.BloggerApplication;
import androidx.gdata.blogger.Blog;
import androidx.gdata.blogger.BlogEntryCollection;
import androidx.util.GUITask;
import androidx.util.GUITaskQueue;
import androidx.util.ProgressIndicator;

public class GetBlogEntriesTask implements GUITask {
	private Blog blog;
	private AsyncCallback<BlogEntryCollection> callback;
	private BlogEntryCollection blogEntries;

	public GetBlogEntriesTask(Blog blog, AsyncCallback<BlogEntryCollection> callback) {
		this.blog = blog;
		this.callback = callback;
	}
	
	public void executeNonGuiTask() throws Exception {
		blogEntries = BloggerApplication.getInstance().getServer().getBlogEntries(blog);
	}

	public void after_execute() {
		callback.onSuccess(blogEntries);
	}

	
	public void onFailure(Throwable t) {
		callback.onFailure(t);
	}

	public static void execute(ProgressIndicator progressIndicator, Blog blog, AsyncCallback<BlogEntryCollection> callback) {
		GUITaskQueue.getInstance().addTask(progressIndicator, new GetBlogEntriesTask(blog, callback));
	}
}
